<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>{$title|default=''}{if !empty($title)} · {/if}{:sysconf('site_name')}</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="{:sysconf('browser_icon')}" />
    <!--<link rel="stylesheet" href="__STATIC__/plugs/awesome/css/font-awesome.min.css?ver={:date('ymd')}">-->
    <!--<link rel="stylesheet" href="__STATIC__/plugs/bootstrap/css/bootstrap.min.css?ver={:date('ymd')}"/>-->
    <link rel="stylesheet" href="__STATIC__/plugs/layui/css/layui.css?ver={:date('ymd')}" />
    <!--<link rel="stylesheet" href="__STATIC__/theme/default/css/console.css?ver={:date('ymd')}">-->
    <!--<link rel="stylesheet" href="__STATIC__/theme/default/css/animate.css?ver={:date('ymd')}">-->
    <!--<script src="__STATIC__/plugs/require/require.js?ver={:date('ymd')}"></script>-->
    <!--<script src="__STATIC__/admin/app.js?ver={:date('ymd')}"></script>-->
    <script src="__STATIC__/plugs/jquery/jquery.min.js?ver={:date('ymd')}"></script>
    <script src="__STATIC__/plugs/jquery/jquery.jqprint-0.3.js?ver={:date('ymd')}"></script>
    <!--<script>window.ROOT_URL = '__PUBLIC__';</script>-->
    <style media="print">
        @page {
            size: auto;
            margin: 0mm;
        }
    </style>
    <style>
        #goods_list {
            overflow-y: scroll;
            height: 400px;
        }

        #goods_list li {
            border-radius: 10px;
            border: 1px solid #e2e2e2;
            width: 100px;
            height: 80px;
            float: left;
            padding: 20px;
        }

        #goods_list>li>span {
            vertical-align: middle;
            display: inline-block;
            text-align: center;
        }

        #goods_list>li>p {
            text-align: center;
        }

        #goods_list>li>p:nth-of-type(1) {}

        #goods_list>li>p:nth-of-type(2) {}

        #goods_list>li>p:nth-of-type(3) {}

        #goods_list li:nth-child(odd) {
            background: #fff;
        }

        #goods_list li:nth-child(even) {
            background: #f2f2f2;
        }

        .layui-form-item {
            border: 0 !important;
        }

        .cur_goods {
            background-color: #f2f2f2 !important;
        }

        .goods_list_empty {
            text-align: center;
            line-height: 350px;
        }


        .layui-input-block>a {
            margin-left: 0 !important;
            margin-bottom: 10px;
        }

        #layui-input-block1 {
            margin-left: 0 !important;
        }

        #layui-inline>div>div {
            margin: 0 !important;
        }


        /* 商品左侧列表 */

        .goods_list_list_headline {
            line-height: 40px;
            background: #f2f2f2;
        }

        .goods_list_list_headline span {
            line-height: 40px;
            display: inline-block;
            vertical-align: middle;
            text-align: center;
        }

        .goods_list_list_headline span:nth-of-type(1) {
            width: 140px;
        }

        .goods_list_list_headline span:nth-of-type(2) {
            width: 300px;
        }

        .goods_list_list_headline span:nth-of-type(3) {
            width: 75px;
        }

        .goods_list_list_headline span:nth-of-type(4) {
            width: 75px;
        }

        .goods_list_list_headline span:nth-of-type(5) {
            width: 75px;
        }

        /* 商品循环 */

        .goods_list_list {
            line-height: 40px;
            -webkit-transition: all .3s;
            height: 400px;
            overflow-y: scroll;
        }

        .goods_list_list p {
            border-top: 1px solid #e2e2e2;
            padding: 5px 0 5px 0;
        }

        .goods_list_list span {
            line-height: 40px;
            display: inline-block;
            vertical-align: middle;
            text-align: center;
        }

        .goods_list_list span:nth-of-type(1) {
            width: 140px;

        }

        .goods_list_list span:nth-of-type(2) {
            width: 300px;
        }

        .goods_list_list span:nth-of-type(3) {
            width: 75px;
        }

        .goods_list_list span:nth-of-type(4) {
            width: 75px;
        }

        .goods_list_list span:nth-of-type(5) {
            width: 75px;
        }
    </style>

</head>

<body>
    <blockquote class="layui-elem-quote">
        <span>{$store.title}</span>
        <a href="javascript:;" class='layui-btn layui-btn-small layui-btn-danger' style="float:right;" onclick="logout()">
            <i class='fa fa-remove'></i> 退出登录
        </a>
        <!--<button  data-title="会员充值" class='layui-btn layui-btn-small' onclick="recharge()" style="float:right;">-->
        <!--<i class='fa fa-plus'></i> 会员充值-->
        <!--</button>-->
        <!--<button  data-title="会员充值" class='layui-btn layui-btn-small' onclick="print_1()" style="float:right;">-->
        <!-- <i class='fa fa-plus'></i> 打印 -->
        <!--</button>-->
    </blockquote>
    <!--<blockquote class="layui-elem-quote">-->
    <!--<span>{$store.title}</span>-->
    <!--<a href="javascript:;" class='layui-btn layui-btn-small layui-btn-danger' style="float:right;" onclick="logout()">-->
    <!--<i class='fa fa-remove'></i> 退出登录-->
    <!--</a>-->
    <!--&lt;!&ndash;<button  data-title="会员充值" class='layui-btn layui-btn-small' onclick="recharge()" style="float:right;">&ndash;&gt;-->
    <!--&lt;!&ndash;<i class='fa fa-plus'></i> 会员充值&ndash;&gt;-->
    <!--&lt;!&ndash;</button>&ndash;&gt;-->
    <!--&lt;!&ndash;<button  data-title="会员充值" class='layui-btn layui-btn-small' onclick="print_1()" style="float:right;">&ndash;&gt;-->
    <!--&lt;!&ndash;<i class='fa fa-plus'></i> 打印&ndash;&gt;-->
    <!--&lt;!&ndash;</button>&ndash;&gt;-->
    <!--</blockquote>-->
    <form class="layui-form layui-form-pane " action="{:url('Index/pay_order')}" method="post" id="form1">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-xs7">
                <div class="grid-demo grid-demo-bg1">
                    <div class="">
                        <label class="layui-form-label">会员账号</label>
                        <div class="layui-input-block" style="position:  relative;">
                            <input id="member" type="text" name="member" placeholder="会员卡号 / 输入手机号" lay-verify="" autocomplete="off" class="layui-input">
                            <span onclick="search();" style="display:block;position: absolute;right:0;height:38px;cursor: pointer;background: #009688;top: 0;color: #fff;width: 70px;text-align:  center;line-height: 38px;">搜索</span>
                        </div>
                    </div>
                </div>
                <div class="grid-demo grid-demo-bg1">
                    <div class="">
                        <label class="layui-form-label" style="border-top: 0;">支付码</label>
                        <div class="layui-input-block" style="border-top: 0;">
                            <input id="auth_code" style="border-top: 0;" type="text" name="auth_code" placeholder="扫描付款码 微信/支付宝" lay-verify="" autocomplete="off"
                                class="layui-input" onchange="get_auth_code(this)">
                        </div>
                    </div>
                </div>
                <!-- <table class="layui-table" lay-skin="line" id="lst">
                    <thead>
                        <tr colspan="6">
                            <th style="text-align: center;">购买商品</th>
                        </tr>
                    </thead>
                </table> -->
                <div class="grid-demo grid-demo-bg1">
                    <div class="layui-table" style="border: 1px solid #e2e2e2;">
                        <div class="goods_list_list_headline">
                            <span>商品</span>
                            <span>规格</span>
                            <span>价格</span>
                            <span>数量</span>
                            <span>操作</span>
                        </div>
                        <div class="goods_list_list select_goods_list">
                            <!--                             
                            <p class="select_goods ">
                                <span onclick="chose_goods(this);">朗姆芝士</span>
                                <span onclick="chose_goods(this);">温度: 低温,糖度: 多糖</span>
                                <span onclick="chose_goods(this);">0.00</span>
                                <span onclick="chose_goods(this);">1</span>
                                <span>
                                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="cancel_goods(this)">×</a>
                                </span>
                            </p> -->
                        </div>
                    </div>

                </div>
            </div>
            <div class="layui-col-xs5">
                <fieldset class="layui-elem-field" style="display:none;">
                    <legend style="font-size:larger">会员信息</legend>
                    <div class="layui-field-box">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">姓名</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="realname" autocomplete="off" class="layui-input" value="" readonly>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">余额</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="balance" autocomplete="off" class="layui-input" value="" readonly>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">电话</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="mobile" autocomplete="off" class="layui-input" value="" readonly>
                                </div>
                            </div>
                        </div>
                    </div>
                </fieldset>
                <div class="" pane>
                    <div class="grid-demo">
                        <table class="layui-table" lay-skin="line">
                            <thead>
                                <tr colspan="6">
                                    <th style="text-align: center;">商品分类</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                    <div class="layui-inline" id="layui-inline">
                        <div>
                            {foreach name="goods_category" item="v"}
                            <input type="radio" name="gat_id" lay-filter="category" value="{$v.id}" title="{$v.title}" onclick="select_catrgory({$v.id})"> {/foreach}
                        </div>
                    </div>
                </div>
                <div class="grid-demo">
                    <!-- <table class="layui-table" lay-skin="line">
                        <thead>
                            <tr colspan="6">
                                <th style="text-align: center;">商品列表</th>
                            </tr>
                        </thead>
                    </table> -->
                    <!--商品信息处 start-->
                    <ul id="goods_list">
                        <p class="goods_list_empty">请选择商品</p>
                    </ul>
                    <!--商品信息 end-->
                </div>
                <!--分页区 start-->
                <div class="layui-form-item" pane style="text-align: right;">
                    <div class="layui-inline" id="fpage">

                    </div>
                </div>
                <!--分页区 end-->
            </div>
        </div>
        <input type="hidden" name="pay_type" value="">
    </form>
    <form class="layui-form layui-form-pane " action="" method="post" id="form2 " style="width: 100%;overflow: hidden;">
        <div class="layui-form layui-form-pane layui-col-space15">
            <div class="layui-col-xs7">
                <div class="layui-form-item" pane>
                    <div class="layui-inline">
                        <label class="layui-form-label">收款方式</label>
                        <div class="layui-input-block">
                            <input type="radio" name="method" value="3" lay-filter="pay_type" title="余额" disabled>
                            <input type="radio" name="method" value="2" lay-filter="pay_type" title="微信">
                            <input type="radio" name="method" value="1" lay-filter="pay_type" title="支付宝">
                            <input type="radio" name="method" value="4" lay-filter="pay_type" title="现金">
                            <!--<input type="radio" name="method" value="5" lay-filter="pay_type" title="银行卡">-->
                        </div>
                    </div>
                </div>
                <div>
                    <div class="grid-demo grid-demo-bg1">
                        <div class="layui-form-item">
                            <div class="">
                                <label class="layui-form-label" style="width: 70px;">总计</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="all_amount" autocomplete="off" class="layui-input" readonly value="0">
                                </div>
                            </div>
                            <div class="">
                                <label class="layui-form-label" style="width: 70px;">实收</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="final_amount" autocomplete="off" class="layui-input" value="0" onkeyup="chenge_zhaoling()" >
                                </div>
                            </div>
                            <div class="">
                                <label class="layui-form-label" style="width: 70px;">现金</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="credit" autocomplete="off" class="layui-input" value="0" onkeyup="chenge_zhaoling(this)">
                                </div>
                            </div>
                            <div class="">
                                <label class="layui-form-label" style="width: 70px;">找零</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="zhaoling" autocomplete="off" class="layui-input" readonly value="0">
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

            <div class="layui-col-xs5">
                <div class="layui-form-item">
                    <div class="layui-input-block" id="layui-input-block1">
                        <a type="button" class="layui-btn layui-btn-primary" onclick="clean_cash()">清空收银台</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="set_num(1)">1</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="set_num(2)">2</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="set_num(3)">3</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="set_num(4)">4</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="add(1)">+1</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="add(2)">+2</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="add(3)">+3</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="desc(1)">-1</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="desc(2)">-2</a>
                        <a class="layui-btn" lay-submit lay-filter="add1" onclick="desc(3)">-3</a>
                        <a class="layui-btn" lay-submit lay-filter="demo1" onclick="check_form();">结账</a>

                    </div>
                </div>
                <!-- <div class="layui-form-item">
                <div class="layui-input-block">
                    <a type="button" class="layui-btn layui-btn-primary" onclick="clean_cash()">清空收银台</a>
                    <a class="layui-btn" lay-submit lay-filter="demo1" onclick="check_form();">结账</a>
                </div>
            </div> -->
            </div>

        </div>

        <input type="hidden" name="uid" value="">
        <input type="hidden" name="auth_code" value="">

    </form>

    <div style="display: none">
        <div id="print-area">
            <table id="print">
            </table>
        </div>
    </div>
    <script src="__STATIC__/plugs/layui/layui.all.js" charset="utf-8"></script>
    <script>
        //ajax查询商品信息
        layui.use('form', function () {
            var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
            form.render();
            form.on('radio(category)', function (data) { //根据商品分类选择商品
                var cat_id = data.value;
                $.post("{:url('Index/get_goods')}", //ajax查询商品信息
                    {
                        cat_id: cat_id
                    },
                    function (data) {
                        if (data.code == 1) {
                            var data = data.data;
                            layui.use(['laypage', 'layer'], function () {
                                var laypage = layui.laypage,
                                    layer = layui.layer;

                                //                                //总页数大于页码总数
                                //                                laypage.render({
                                //                                    elem: 'demo20',
                                //                                    limit: 6,
                                //                                    count: 70 //数据总数
                                //                                        ,
                                //                                    jump: function (obj) {
                                //                                        console.log(obj)
                                //                                    }
                                //                                });
                                //测试数据

                                //调用分页
                                laypage.render({
                                    elem: 'fpage',
                                    count: data.length,
                                    limit: 9,
                                    groups: 1,
                                    jump: function (obj) {
                                        //模拟渲染
                                        document.getElementById('goods_list').innerHTML =
                                            function () {
                                                var arr = [],
                                                    thisData = data.concat().splice(
                                                        obj.curr * obj.limit -
                                                        obj.limit, obj.limit);
                                                layui.each(thisData, function (
                                                    index, item) {
                                                    if (item.title ==
                                                        null) {
                                                        var title = '';
                                                    } else {
                                                        var title =
                                                            item.title;
                                                    }
                                                    var html =
                                                        '<li style="width:100px;height:80px;float:left;" onclick="add_goods(this,' +
                                                        item.id +
                                                        ')"  data-price="' +
                                                        item.price +
                                                        '" data-name="' +
                                                        item.name +
                                                        '" data-spec-title="' +
                                                        item.title +
                                                        '"><p>' +
                                                        item.name +
                                                        '</p><p>' +
                                                        title +
                                                        '</p><p>' +
                                                        item.price +
                                                        '</p></li>';
                                                    //<li onclick="add_goods(this,5)" data-price="8.00" data-name="百岁山" data-spec-title="null"><span>百岁山</span><span></span><span>8.00</span></li>

                                                    arr.push(html);
                                                });
                                                return arr.join('');
                                            }();
                                    }
                                });
                            });
                        } else {
                            layer.msg('找不到商品信息', {
                                icon: 2,
                                time: 1000
                            });
                            return false; //重要
                        }
                    }
                );
            });

            form.on('radio(pay_type)', function (data) { //选择支付方式
                $('input[name=pay_type]').val(data.value);
            });

        });
        /**
         * 选择商品
         * id  store_goods_stock - id
         */
        function add_goods(obj, id) {

            var price = parseFloat($(obj).attr('data-price')).toFixed(2); //商品价格,普通会员价格
            var name = $(obj).attr('data-name');
            var spec_title = $(obj).attr('data-spec-title');
            var all_amount = parseFloat($('input[name=all_amount]').val()).toFixed(2); //总金额
            var final_amount = parseFloat($('input[name=final_amount]').val()).toFixed(2); //最终支付金额
            var credit = parseFloat($('input[name=credit]').val()).toFixed(2); //收到的现金
            var zhaoling = parseFloat($('input[name=zhaoling]').val()).toFixed(2); //找零
            all_amount = parseFloat(parseFloat(all_amount) + parseFloat(price)).toFixed(2);
            final_amount = parseFloat(parseFloat(final_amount) + parseFloat(price)).toFixed(2);
            zhaoling = parseFloat(parseFloat(credit) - parseFloat(final_amount)).toFixed(2);

            if ($('input[name=num_' + id + ']').val() != undefined) { //已经选中商品，则在原先基础上面新增
                var price = parseFloat($(obj).attr('data-price')).toFixed(2); //商品价格,普通会员价格
                var num = parseInt($('input[name=num_' + id + ']').val()); //原先的商品数量
                num = parseInt(parseInt(num) + 1);
                $('input[name=num_' + id + ']').val(num);
                $('p[data-id=' + id + ']').attr('data-num', num);
                $('p[data-id=' + id + ']').find('.num').text(num);
                $('.select_goods').removeClass('cur_goods'); //移除选种商品的属性
                $('p[data-id=' + id + ']').addClass('cur_goods');
            } else {
                if (spec_title == 'null') {
                    spec_title = '无';
                }

                var html = '<p class="select_goods cur_goods" data-id="' + id + '" data-price="' + price +
                    '" data-num="1"><span onclick="chose_goods(this);">' + name +
                    '</span><span onclick="chose_goods(this);">' + spec_title +
                    '</span><span  class="price" onclick="chose_goods(this);   ">' + price +
                    '</span><span  class="num" onclick="chose_goods(this);">1</span><span><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="cancel_goods(this)">×</a></span><input type="hidden" name="ids[]" value="' +
                    id + '" ><input type="hidden" name="num_' +
                    id + '" value="1"></p>';
                $('.select_goods').removeClass('cur_goods'); //移除选种商品的属性
                $('.select_goods_list').append(html); //追加元素
            }

            //            console.log('id', id);
            //            console.log('name', name);
            //            console.log('spec_title', spec_title);
            //            console.log('price', price);

            $('input[name=all_amount]').val(all_amount);
            $('input[name=final_amount]').val(final_amount);
            $('input[name=credit]').val(credit);
            $('input[name=zhaoling]').val(zhaoling);

            //            $(obj).removeAttr('onclick');
        }





        /**
         * 设置商品数量
         * @param num
         */
        function set_num(num) {
            var id = $('.cur_goods').attr('data-id');
            if (id == undefined) { //没选中商品防止操作
                return false;
            }

            var price = parseFloat($('.cur_goods').attr('data-price')).toFixed(2);
            var goods_num = parseInt($('.cur_goods').attr('data-num'));

            var all_amount = parseFloat($('input[name=all_amount]').val()).toFixed(2);
            var final_amount = parseFloat($('input[name=final_amount]').val()).toFixed(2);
            var credit = parseFloat($('input[name=credit]').val()).toFixed(2);
            var zhaoling = parseFloat($('input[name=zhaoling]').val()).toFixed(2);
            var old_price = parseFloat(price * goods_num).toFixed(2);
            var cur_price = parseFloat(price * num).toFixed(2);
            console.log(cur_price);
            console.log(old_price);
            console.log(goods_num);

            all_amount = parseFloat(all_amount) + parseFloat(cur_price - old_price);
            final_amount = parseFloat(final_amount) + parseFloat(cur_price - old_price);
            zhaoling = parseFloat(credit) - parseFloat(final_amount);
            $('input[name=all_amount]').val(parseFloat(all_amount).toFixed(2));
            $('input[name=final_amount]').val(parseFloat(final_amount).toFixed(2));
            $('input[name=zhaoling]').val(parseFloat(zhaoling).toFixed(2));

            $('.cur_goods').attr('data-num', num); //更新操作的商品的数量属性
            $('.cur_goods').find('.num').text(num);
            $('input[name=num_' + id + ']').val(num);
        }

        /**
         * 增加商品数量
         */
        function add(num) {
            var id = $('.cur_goods').attr('data-id');
            if (id == undefined) { //没选中商品防止操作
                return false;
            }

            var price = parseFloat($('.cur_goods').attr('data-price')).toFixed(2);
            var goods_num = parseInt($('.cur_goods').attr('data-num'));

            var all_amount = parseFloat($('input[name=all_amount]').val()).toFixed(2);
            var final_amount = parseFloat($('input[name=final_amount]').val()).toFixed(2);
            var credit = parseFloat($('input[name=credit]').val()).toFixed(2);
            var zhaoling = parseFloat($('input[name=zhaoling]').val()).toFixed(2);
            var old_price = parseFloat(price * goods_num).toFixed(2); //以前的商品价格


            var cur_price = parseFloat(price * num).toFixed(2);
            var cur_num = parseInt(goods_num + num);
            //        console.log(cur_price);
            //        console.log(old_price);
            //        console.log(all_amount);

            all_amount = parseFloat(all_amount) + parseFloat(cur_price);
            final_amount = parseFloat(final_amount) + parseFloat(cur_price);
            zhaoling = parseFloat(credit) - parseFloat(final_amount);
            $('input[name=all_amount]').val(parseFloat(all_amount).toFixed(2));
            $('input[name=final_amount]').val(parseFloat(final_amount).toFixed(2));
            $('input[name=zhaoling]').val(parseFloat(zhaoling).toFixed(2));

            $('.cur_goods').attr('data-num', cur_num); //更新操作的商品的数量属性
            $('.cur_goods').find('.num').text(cur_num);
            $('input[name=num_' + id + ']').val(cur_num);
        }
        /**
         * 找零
         */
        function chenge_zhaoling() {
            var xianjin = parseFloat($('input[name=credit]').val()).toFixed(2); //收到现金
            var final_amount = parseFloat($('input[name=final_amount]').val()).toFixed(2);
            if (final_amount == 'NaN') {
                final_amount = parseFloat(0);
            }
            if (xianjin == 'NaN') {
                xianjin = parseFloat(0);
            }
            var zhaoling = parseFloat(xianjin - final_amount).toFixed(2);
            $('input[name=zhaoling]').val(zhaoling);
        }

        /**
         * 减少商品数量
         */
        function desc(num) {
            var id = $('.cur_goods').attr('data-id');
            if (id == undefined) { //没选中商品防止操作
                return false;
            }

            var price = parseFloat($('.cur_goods').attr('data-price')).toFixed(2);
            var goods_num = parseInt($('.cur_goods').attr('data-num'));

            if (goods_num <= num) { //防止剪成负数
                return false;
            }

            var all_amount = parseFloat($('input[name=all_amount]').val()).toFixed(2);
            var final_amount = parseFloat($('input[name=final_amount]').val()).toFixed(2);
            var credit = parseFloat($('input[name=credit]').val()).toFixed(2);
            var zhaoling = parseFloat($('input[name=zhaoling]').val()).toFixed(2);
            var old_price = parseFloat(price * goods_num).toFixed(2); //以前的商品价格


            var cur_price = parseFloat(price * num).toFixed(2);
            var cur_num = parseInt(goods_num - num);
            //        console.log(cur_price);
            //        console.log(old_price);
            //        console.log(all_amount);

            all_amount = parseFloat(all_amount) - parseFloat(cur_price);
            final_amount = parseFloat(final_amount) - parseFloat(cur_price);
            zhaoling = parseFloat(credit) - parseFloat(final_amount);
            $('input[name=all_amount]').val(parseFloat(all_amount).toFixed(2));
            $('input[name=final_amount]').val(parseFloat(final_amount).toFixed(2));
            $('input[name=zhaoling]').val(parseFloat(zhaoling).toFixed(2));

            $('.cur_goods').attr('data-num', cur_num); //更新操作的商品的数量属性
            $('.cur_goods').find('.num').text(cur_num);
            $('input[name=num_' + id + ']').val(cur_num);
        }

        /**
         * 删除商品
         * @param obj
         */
        function cancel_goods(obj) {
            var price = parseFloat($(obj).parent().parent().attr('data-price')).toFixed(2);
            var goods_num = parseInt($(obj).parent().parent().attr('data-num'));

            var all_amount = parseFloat($('input[name=all_amount]').val()).toFixed(2);
            var final_amount = parseFloat($('input[name=final_amount]').val()).toFixed(2);
            var credit = parseFloat($('input[name=credit]').val()).toFixed(2);
            var zhaoling = parseFloat($('input[name=zhaoling]').val()).toFixed(2);

            var old_price = parseFloat(goods_num * price).toFixed(2);

            all_amount = parseFloat(parseFloat(all_amount) - parseFloat(old_price)).toFixed(2);
            final_amount = parseFloat(parseFloat(final_amount) - parseFloat(old_price)).toFixed(2);
            zhaoling = parseFloat(parseFloat(credit) - parseFloat(final_amount)); //找零

            $('input[name=all_amount]').val(all_amount);
            $('input[name=final_amount]').val(final_amount);
            $('input[name=zhaoling]').val(zhaoling);

            $(obj).parent().parent().remove();
        }

        /**
         * 选中或取消选中商品
         */
        function chose_goods(obj) {
            if ($(obj).parent().hasClass('cur_goods')) {
                $(obj).parent().parent().removeClass('cur_goods');
            } else {
                $('.select_goods').removeClass('cur_goods');
                $(obj).parent().addClass('cur_goods');
            }
        }

        /**
         * 查找会员信息
         */
        //        function find() {
        //            $.post("{:url('Index/member')}", {
        //                    no: $('#member').val()
        //                }, //会员账号
        //                function (data) {
        //                    if (data.code == 1) {
        //                        alert('sss');
        //                        if (data.balance > 0) { //会员余额大于0
        //                            //                            $('input:radio[name="method"][title="余额"]').attr("checked", "checked");
        //                            $("input[title = '余额']").removeAttr("disabled");
        //                            //                        $("input:radio[title!='余额']").attr("disabled", 'disabled');
        //                        } else {
        //                            $('input:radio[name="method"]').removeAttr("disabled");
        //                            $('input:radio[name="method"][title="余额"]').attr("checked", false);
        //                            //                        $("input[title = '余额']").attr("disabled", 'disabled');
        //                        }
        //                        $('input[name=balance]').val(data.balance);
        //                        $('input[name=realname]').val(data.realname);
        //                        $('input[name=mobile]').val(data.mobile);
        //                        $('input[name=uid]').val(data.uid);
        //
        //                        var form = layui.form;
        //                        form.render('select'); //刷新select选择框渲染
        //                        form.render('radio'); //刷新radio选择框渲染
        //                    }
        //                }
        //            );
        //        }

        /**
         * 获得会员支付授权码
         */
        function get_auth_code(obj) {
            var value = $(obj).val();
            $('input[name=auth_code]').val(value);
            //        $(obj).unbind('onchange');
            //        $(obj).val('扫码成功');
            //        $(obj).attr('readonly',true);
        }
        /**
         * 清空收银台
         */
        function clean_cash() {
            location.reload();
        }
        /**
         * 查询订单
         */
        function check_form() {
            var ids_len = $('input[name="ids[]"]').length; //选中的商品的个数
            var method = $('input[name=method]:checked').val(); //支付方式
            var uid = $('input[name=uid]').val(); //会员信息
            var auth_code = $('input[name=auth_code]').val(); //会员支付码
            var final_amount = parseFloat($('input[name=final_amount]').val()).toFixed(2); //最终支付价
            var xianjin = parseFloat($('input[name=credit]').val()).toFixed(2);
            var mobile = $('#member').val();
            console.log(final_amount);
            console.log(xianjin);
            if (ids_len == 0) {
                layer.msg('请选择商品', {
                    icon: 2,
                    time: 1000
                });
                return false; //重要
            }

            if (method == undefined) {
                layer.msg('请选择付款方式', {
                    icon: 2,
                    time: 1000
                });
                return false; //重要
            }

            //            if (method == 4) {
            //                if (xianjin < final_amount) {
            //                    layer.msg('现金不足，不能支付', {
            //                        icon: 2,
            //                        time: 1000
            //                    }) ;
            //                    return false; //重要
            //                }
            //            }

            var ids = new Array(); //商品的数量
            var nums = new Array(); //商品数量
            var goods_specs = ''; //提交的json数据
            $('input[name^=num_]').each(function (index, item) {
                var k = index;
                var arr = new Array();
                var key = $(this).attr('name'); //元素的名称
                var value = $(this).val(); //元素的值
                var id = $(this).prev().val(); //上一个兄弟元素的id
                ids.push(id);
                nums.push(value);
                //            if(index!=0){
                //                num_json += ",";
                //            }
                //            num_json += '{\"num\":' +value+ ',\"ids\":\"' +id+ '\"}';
            });
            //        var num_arr= eval("[" + num_json + "]");
            console.log(goods_specs);
            $.post("{:url('Index/pay_order')}", {
                    pay_type: method,
                    nums: nums,
                    ids: ids,
                    uid: uid,
                    auth_code: auth_code,
                    final_amount: final_amount,
                    mobile:mobile
                },
                function (data) {
                    if (data.code == 1) {
                        if (data.msg == 3) {
                            $('#print').html(data.data);
                            print();
                            location.reload();
                        } else if (data.msg == 2) {
                            $('#print').html(data.data);
                            print();
                            location.reload();
                        } else {
                            $('#print').html(data.data);
                            print();
                            location.reload();
                        }
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1000
                        });
                        return false; //重要
                    }
                }
            );
        }



        /**
         * 打印小票
         */
        function print() {
            if (!!window.ActiveXObject || "ActiveXObject" in window) {
                remove_ie_header_and_footer();
            }
            var newWindow = window.open("打印窗口", "_blank");
            var docStr = $("#print-area").html();
            newWindow.document.write(docStr);
            newWindow.document.close();
            newWindow.print();
            newWindow.close();
            //        $("#print-area").jqprint({
            //            debug: false,
            //            importCSS: true,
            //            printContainer: true,
            //            operaSupport: false
            //        });
        }
        /**
         * 取出打印的页眉页脚
         */
        function remove_ie_header_and_footer() {
            var hkey_root, hkey_path, hkey_key;
            hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
            try {
                var RegWsh = new ActiveXObject("WScript.Shell");
                RegWsh.RegWrite(hkey_path + "header", "");
                RegWsh.RegWrite(hkey_path + "footer", "");
            } catch (e) {}
        }

        /**
         * 退出登录
         */
        function logout() {
            layer.confirm('确定退出登录吗？', {
                btn: ['确定', '取消']
            }, function () {
                $.post("{:url('Index/out')}", {
                        id: 1
                    },
                    function (data) {
                        if (data.code == 1) {
                            layer.msg('退出登录成功', {
                                icon: 1,
                                time: 1000
                            }, function (data) {
                                window.location.href = "{:url('Login/index')}";
                            });
                        } else {
                            layer.msg('网络请求失败，请稍后再试', {
                                icon: 2
                            });
                        }
                    }
                );
            }, function () {});
        }
        /**
         * 查询会员信息
         */
        function search() {
            $.post("{:url('Index/member')}", {
                    no: $('#member').val()
                }, //会员账号
                function (data) {
                    if (data.code == 1) {
                        if (data.data.balance > 0) { //会员余额大于0
                            //                            $('input:radio[name="method"][title="余额"]').attr("checked", "checked");
                            $("input[title = '余额']").removeAttr("disabled");
                            //                        $("input:radio[title!='余额']").attr("disabled", 'disabled');
                        } else {
                            $('input:radio[name="method"]').removeAttr("disabled");
                            $('input:radio[name="method"][title="余额"]').attr("checked", false);
                            //                        $("input[title = '余额']").attr("disabled", 'disabled');
                        }
                        $('input[name=balance]').val(data.data.balance);
                        $('input[name=realname]').val(data.data.realname);
                        $('input[name=mobile]').val(data.data.mobile);
                        $('input[name=uid]').val(data.data.uid);

                        var form = layui.form;
                        form.render('select'); //刷新select选择框渲染
                        form.render('radio'); //刷新radio选择框渲染
                    } else {
                        layer.msg('找不会员信息，请重新输入', {
                            icon: 2,
                            time: 1000
                        });
                        return false; //重要
                    }
                }
            );
        }
    </script>
</body>

</html>